home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / cenvid.zip / KEYSTATE.BAT < prev    next >
DOS Batch File  |  1993-05-25  |  2KB  |  65 lines

  1. @echo off
  2. REM KeyState - Macro to set, unset, or display the state of keys.
  3. cenvi %0.bat %1 %2 %3 %4
  4. GOTO CENVI_EXIT
  5.  
  6. #define  NUMLOCK_BIT    0x20
  7. #define  CAPSLOCK_BIT   0x40
  8. #define  KEYS_SEGMENT   0x0040
  9. #define  KEYS_OFFSET    0x0017
  10. KeysAddress = Address(KEYS_SEGMENT,KEYS_OFFSET)
  11.  
  12. main(argc,argv)
  13. {
  14.    // check that the input is valid
  15.    if ( argc != 3
  16.      || ( argv[1][1] != 0  ||  !strchr("+?-",argv[1][0]) )
  17.      || ( strnicmp("CAP",argv[2],3)  &&  strnicmp("NUM",argv[2],3) ) ) {
  18.       Instructions()
  19.    } else {
  20.       // determine whether to apply to CapsLock or NumLock
  21.       if ( !strnicmp("CAP",argv[2],3) ) {
  22.          KeyName = "CapsLock", KeyBit = CAPSLOCK_BIT
  23.       }
  24.       else {
  25.          KeyName = "NumLock",  KeyBit = NUMLOCK_BIT
  26.       }
  27.       // perform action on the selected key
  28.       CurrentState = peek(KeysAddress)
  29.       switch( argv[1][0] ) {
  30.          case '+':   // Set Key ON
  31.             poke(KeysAddress,CurrentState | KeyBit)
  32.             break
  33.          case '-':   // Turn KEY OFF
  34.             poke(KeysAddress,CurrentState & ~KeyBit)
  35.             break
  36.          case '?':   // display and return state of key
  37.             printf("%s is currently set %s.\n",KeyName,CurrentState & KeyBit ? "ON" : "OFF")
  38.             return( CurrentState & KeyBit ? 1 : 0 )
  39.       }
  40.    }
  41. }
  42.  
  43.  
  44. Instructions()
  45. {
  46.    printf("\a\n")
  47.    printf("KeyState - Set, Clear, or Show the keyboard state of NumLock or CapsLock\n");
  48.    printf("\n");
  49.    printf("SYNTAX: KeyState < + | - | ? > < CAP | NUM >\n");
  50.    printf("\n");
  51.    printf("Where:  +    Set KeyState ON\n");
  52.    printf("        -    Set KeySTate OFF\n");
  53.    printf("        ?    Display current Key State, and return ERRORLEVEL 1 if set\n");
  54.    printf("             and ERRORLEVEL 0 if clear\n");
  55.    printf("        NUM  Apply comman < + | - | ? > to the NumLock key\n");
  56.    printf("        CAP  Apply comman < + | - | ? > to the CapsLock key\n");
  57.    printf("\n");
  58.    printf("Examples: KeyState + Num      Turn on the Numlock key\n");
  59.    printf("          KeyState - Cap      Turn of the CapsLock key\n");
  60.    printf("          KeyState ? Num      Show state of NumLock, return ERRORLEVEL if set\n");
  61.    printf("\n")
  62. }
  63.  
  64. :CENVI_EXIT
  65.